import UIKit
//存储属性
//类
class Role {
    var name = ""
    var money = 0
}
let xiaobo = Role()
xiaobo.name = "小波"
xiaobo.money = 5000

//计算属性
//结构体
struct Point {
    var x = 0, y = 0
}
//枚举
enum MovePatterns {
    case walk
    case run
    case horse
    case teleport
}


class Magician: Role {
    
    var rolePoint = Point()
    var move = MovePatterns.walk
    var currentPoint : Point {
        get {
              switch move {
                case .walk:
                    rolePoint.x += 1
                    rolePoint.y += 1
                case .run:
                    rolePoint.x += 3
                    rolePoint.y += 3
                case .horse:
                    rolePoint.x += 10
                    rolePoint.y += 10
                case .teleport:
                    rolePoint.x += 1000
                    rolePoint.y += 1000
            }
            return rolePoint
    }
        
        set {
            rolePoint = newValue
        }
    }
  
}

var m1 = Magician()
m1.currentPoint

m1.move = .run
m1.currentPoint

m1.move = .run
m1.currentPoint

m1.move = .teleport
m1.currentPoint


m1.currentPoint = Point(x: 3000, y: 90)
m1.currentPoint

//属性监视器
//willSet事前响应，新值newValue
//didSet:事后响应，旧值oldValue

struct exp {
    var total = 0 {
        willSet {
            print("当前总经验",newValue)
        }
        didSet {
            print("共增加了",total - oldValue,"点")
        }
    }
}

var exp1 = exp()
exp1.total = 1000
exp1.total = 3000

//类型属性：属于类型固有的，实力不能调用。属性定义前加关键字static
//对于类，只支持计算型的类型属性，前面加关键字class可被子类重写（override）

struct Shopping {
    static let 试衣间 = "Uniclo"
    static let web = "http://www.taobao.com?cate="
    var cate = ""
    var shareUrl : String {
        return Shopping.web + cate
    }
}

//如果调用固定属性，比如说要调用试衣间这个属性，那么就不需要实例化Shopping这个类
Shopping.试衣间

//如果想要调用shareUrl这个属性，那么必须先实例化这个Shopping类
let shop1 = Shopping(cate: "海鲜")
shop1.shareUrl

class Life {
//    static var gene = "DNA"
    class var gene : String {
        return "DNA"
    }
}
Life.gene

class Bateria : Life {
//    static var gene = "RNA"
    override class var gene : String {
        return "RNA"
    }
}

Bateria.gene


//方法，函数

enum MonExp : Int {
    case kulou = 80,zhifukukou = 100, kuloujiaozhu = 800
}

struct ServerExp {
    var onoff = false
    var times = 1
}

class RichPlayer {
    var exp = 0 {
        didSet {
            print("增加了",exp - oldValue)
        }
    }
    var times = ServerExp()
    func idleExp() {
        exp += 1000
        print("成功挂机一次，经验增加了",exp,"点")
    }
    func killMonster(monster:MonExp, times: Int) {
        let monExp = monster.rawValue
        self.exp += monExp * times
        if self.times.onoff && self.times.times > 1 {
            self.exp *= self.times.times
        }
        print("当前打怪经验是",self.exp)
    }
}

var xiaodou = RichPlayer()
xiaodou.idleExp()
xiaodou.killMonster(monster: MonExp.kuloujiaozhu, times: 1)

xiaodou.times.onoff = true
xiaodou.times.times = 15
xiaodou.killMonster(monster: MonExp.kulou, times: 3)


//结构体/枚举实例默认不可更改属性值，如果需要修改，请加上mutating关键字

struct RolePointN {
    var x = 0, y = 0
    
mutating func SafeZone(x:Int,y:Int) {
        self.x = x
        self.y = y
        print("已经回到了安全区",self.x,self.y)
    }
}

var xiaoli = RolePointN()
xiaoli.SafeZone(x: 300, y: 300)
xiaoli.x
xiaoli.y


enum GuessGame {
    case ston,knife,cloth
    static let game = "猜拳"
   mutating func start(){
        print("我开始出的是",self)
        switch self {
        case .cloth:
            self = GuessGame.knife
        case .knife:
            self = GuessGame.ston
        case .ston:
             self = GuessGame.cloth
        }
    
    print("我现在出的是",self)

    }
}

var xiaobu = GuessGame.cloth
xiaobu.start()
xiaobu.start()





